package com.llb666.shop.user.api.dto;

import com.llb666.common.core.enums.Sex;
import com.llb666.common.core.utils.DateUtil;
import com.llb666.common.core.utils.sign.MD5Utils;
import com.llb666.shop.user.domain.entity.Users;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * 用户注册dto.
 *
 * @author llb666
 */
@Data
@Schema(description = "用户注册对象")
public class UserRegisterDto {

    @Schema(description = "用户名", example = "maYun", requiredMode = Schema.RequiredMode.REQUIRED)
    private String username;

    @Schema(description = "密码",  example = "123456", requiredMode = Schema.RequiredMode.REQUIRED)
    private String password;

    @Schema(description = "确认密码",  example = "123456", requiredMode = Schema.RequiredMode.REQUIRED)
    private String confirmPassword;


    public static Users covert(String userId, UserRegisterDto userRegisterDto) throws Exception {
        Users user = new Users();
        if(!StringUtils.isEmpty(userId)){
            user.setId(userId);
        }
        user.setUsername(userRegisterDto.getUsername());
        //密码需要MD5加密
        user.setPassword(MD5Utils.getMD5Str(userRegisterDto.getPassword()));
        user.setNickname(userRegisterDto.getUsername());
        user.setBirthday(DateUtil.stringToDate("1900-01-01"));
        user.setSex(Sex.SECRET.type);
        user.setCreatedTime(new Date());
        user.setUpdatedTime(new Date());
        return user;
    }
}
